import { Component, ElementRef, ViewChild } from '@angular/core';
import { MessageService } from '@shared/services/message.service';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-audio-container',
  templateUrl: './audio-container.component.html',
  styleUrl: './audio-container.component.css'
})
export class AudioContainerComponent {
  @ViewChild('audio') audio!: ElementRef;

  constructor(
    private messageService: MessageService,
    private message: NzMessageService
  ) {
    this.messageService.On('bottom-container', (data: { type: string, isClose: boolean }) => {
      if (data.type === 'music') {
        if (data.isClose) {
          this.pause();
        } else {
          this.play()
        }
      }
    })
  }

  play() {
    this.audio.nativeElement.play();
  }

  pause() {
    this.audio.nativeElement.pause();
  }

  playHandle() {
    this.message.warning('音乐已打开')
  }

  pauseHandle() {
    this.message.warning('音乐已关闭')
  }
}
